package com.example.provider.javastudy.thread.common;

/**
 * All rights Reserved, Designed By www.maihaoche.com
 *
 * @Package com.example.demo.thread
 * @author: 红雪（hongxue@maihaoche.com）
 * @date: 2019/1/16 9:13 AM
 * @Copyright: 2017-2020 www.maihaoche.com Inc. All rights reserved.
 * 注意：本内容仅限于卖好车内部传阅，禁止外泄以及用于其他的商业项目
 */
public class Hero {

    public String name;
    public float hp;
    public int damage;

    public void attackHero(Hero hero){

        try {
            Thread.sleep(1000);
            System.out.println("当前线程为:"+Thread.currentThread().toString());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        hero.hp -= this.damage;
        System.out.printf("%s 正在攻击 %s，%s的血量变成了 %.0f %n",name, hero.name,hero.name,hero.hp);
        if (hero.isDead()){
            System.out.println(hero.name+"死了");
        }
    }

    public boolean isDead(){
        return hp<=0;
    }
}
